from django.db import models

# Create your models here.


class Menus(models.Model):
    class Meta:
        db_table = 'menus'
    authName = models.CharField(max_length=10)
    path = models.CharField(max_length=50)
    parent = models.ForeignKey(to="self", on_delete=models.CASCADE,null=True, default=None, related_name='children')


class Rights(models.Model):
    class Meta:
        db_table = 'rights'
    authName = models.CharField(max_length=20)
    level = models.CharField(max_length=1)
    parent_id = models.ForeignKey(to='self', on_delete=models.CASCADE,default=None, null=True,related_name='children')
    path = models.CharField(max_length=10)

    def __str__(self):
        return self.authName


class Roles(models.Model):
    class Meta:
        db_table = 'roles'
    roleName = models.CharField(max_length=10)
    roleDesc = models.CharField(max_length=20)
    right = models.ForeignKey(to=Rights, on_delete=models.CASCADE, null=True)

    def __str__(self):
        return self.roleName


class Users(models.Model):
    class Meta:
        db_table = 'users'
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=20)
    email = models.CharField(max_length=30)
    mobile = models.CharField(max_length=20)
    mg_state = models.BooleanField(default=False)
    role_name = models.ForeignKey(Roles, on_delete=models.CASCADE, null=True)
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.username


class Categories(models.Model):
    class Meta:
        db_table = 'categories'
    cat_name = models.CharField(max_length=20)
    cat_pid = models.ForeignKey(to="self", on_delete=models.CASCADE,null=True, related_name='children')
    cat_level = models.CharField(max_length=1)
    cat_deleted = models.BooleanField(default=True)


